<template>
  <div class="login_box">
    <el-form :model="loginForm" :rules="rules" ref="loginForm">
      <el-form-item label="账号" prop="username" >
        <el-input type="username" v-model="loginForm.username"></el-input>
      </el-form-item>
      <el-form-item label="密码" prop="password">
        <el-input type="password" v-model="loginForm.password"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="login('loginForm')">提交</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>

export default {
  name: 'login',
  methods:{
    login:function(loginForm){
      // 验证登录规则
      this.$refs[loginForm].validate((valid) => {
          if (valid) {
            // 进行登录
            this.$store.commit('saveUser',this.loginForm.username)
            // 关闭登录窗口
            this.loginDialgChange();
          } else {
            // 登录失败
            return false;
          }
        });
    },
    loginDialgChange:function(){
      this.$store.commit('loginDialgChange')
    }
  },
  data(){
    return{
      loginForm:{
        username:'',
        password:''
      },
      rules:{
        username:[{ required: true, message: '请输入账号', trigger: 'blur' }],
        password:[{ required: true, message: '请输入密码', trigger: 'blur' }]
      }
    }
  }
}
</script>

<style scoped>
.login_box{
    height: 100%;
    width: 100%;
    background-color: rgba(255,255,255,0);
}
</style>
